package me.numark.activities;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

import butterknife.Bind;
import me.numark.R;
import me.numark.fragments.BaseListFragment;
import me.numark.fragments.CommentsFragment;
import me.numark.fragments.UserGridFragment;
import me.numark.model.Feed;
import me.numark.model.FeedTag;
import me.numark.utils.Constants;
import me.numark.view.TopicViewHolder;

public class LabelsLikeActivity extends CommentBaseActivity {
    @Bind(R.id.layout_lable_like)
    LinearLayout parentView;

    @Bind(R.id.label_view)
    public View labelView;

    @Bind(R.id.right_image)
    ImageView rightImage;

    private FeedTag mFeedTag;

    TopicViewHolder mTopicViewHolder;

    private BaseListFragment fragment;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        activity_layout_res = R.layout.activity_labels_like;
        super.onCreate(savedInstanceState);
        try {
            mFeedTag = new Gson()
                    .fromJson(getIntent().getStringExtra(Constants.FEEDTAG_EXTRA), FeedTag.class);
        }catch (JsonSyntaxException e){
            e.printStackTrace();
            finish();
        }
        uiInit();
    }

    private void uiInit() {
        fragments = new BaseListFragment[1];
        titleTextView.setText(R.string.detail_title);
        mTopicViewHolder = new TopicViewHolder(labelView, this,TopicViewHolder.STYLE_NORMAL,null,0,Constants.TOPICTYPE_DETAIL);
        mTopicViewHolder.bindData(mFeedTag);
//        inputButton.setOnClickListener(this);
        rightImage.setOnClickListener(this);
        parentView.setOnClickListener(this);
        switchFragment(0);
    }

    public void switchFragment(int i){
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        switch (i){
            case 0:
                //TODO 通过标签id获取点赞列表
                fragment = UserGridFragment.newInstance(1, mFeedTag.id);
//                inputbar.setVisibility(View.GONE);
                break;
        }
        transaction.replace(R.id.fragment_container, fragment);
        transaction.commit();
    }
}
